﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Yipusoft.VehicleReport.BLL;
using Yipusoft.Account.BLL;
using Yipusoft.VehicleReport.Model;
using Yipusoft.Vehicle.Model;
using Yipusoft.Vehicle.BLL;
using Yipusoft.Account.Model;

public partial class Police_SecurityEvaluate_MendstatZD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDepartment();
            BindData();
        }
    }
    void BindDepartment()
    {
        List<DepartmentInfo> departments = Department.GetList("departmentId like '%000' and Departmentid <>'1300000'");
        rblDepartmentId.DataSource = departments;
        rblDepartmentId.DataTextField = "AliasName";
        rblDepartmentId.DataValueField = "departmentid";

        rblDepartmentId.DataBind();
        rblDepartmentId.SelectedIndex = 0;
    }


    void BindData()
    {
        DateTime date = DateTime.Now.Date;
        string DepartmentId = rblDepartmentId.SelectedValue;
        lbldate.Text = date.ToString("yyyy年MM月dd日") + Department.GetDepartment(DepartmentId.Substring(0, 4) + "000").AliasName + "支队车辆检查情况报表";
        if (DepartmentId.Substring(0, 4) != "1300")
        {
            table.Rows.Clear();
            //头
            HtmlTableRow tr = new HtmlTableRow();
            HtmlTableCell td = new HtmlTableCell();
            td.InnerText = "单位";
            td.Width = "15%";
            td.Attributes.Add("style", "border-color:#888888;border-collapse:  collapse; padding: 10px; white-space:nowrap;  border-width: 1px; border-style:solid;text-align: left;");
            tr.Cells.Add(td);

            td = new HtmlTableCell();
            td.InnerText = "车辆";
            td.Width = "18%";
            td.Attributes.Add("style", "border-color:#888888;border-collapse:  collapse; padding: 10px; white-space:nowrap;  border-width: 1px; border-style:solid;text-align: left;");
            tr.Cells.Add(td);

            td = new HtmlTableCell();
            td.Attributes.Add("style", "border-color:#888888;border-collapse:  collapse; padding: 10px; white-space:nowrap;  border-width: 1px; border-style:solid;text-align: left;");
            td.InnerText = "车辆情况";
            tr.Cells.Add(td);

            td = new HtmlTableCell();
            td.Attributes.Add("style", "border-color:#888888;border-collapse:  collapse; padding: 10px; white-space:nowrap;  border-width: 1px; border-style:solid;text-align: left;");
            td.InnerText = "维修完成确认";
            tr.Cells.Add(td);
            table.Rows.Add(tr);


            //车辆损坏单位的单位IDList
            List<string> DepartmentIdList = MendRecord.GetMendDepartmentId(DepartmentId);
            foreach (string SquadronId in DepartmentIdList)
            {
                HtmlTableCell DepartmentCell = new HtmlTableCell();
                DepartmentCell.InnerText = Department.GetDepartment(SquadronId).ShortName;
                DepartmentCell.Attributes.Add("style", "border-color:#888888;border-collapse:  collapse; padding: 10px; white-space:nowrap;  border-width: 1px; border-style:solid;text-align: left;");

                string vecihelWhere = " DepartmentId='" + SquadronId + "' and ZhongdOk='' ";
                List<MendRecordInfo> vehicleList = MendRecord.GetList(vecihelWhere);
                int vehicleCount = vehicleList.Count;
                for (int i = 0; i < vehicleCount; i++)
                {
                    tr = new HtmlTableRow();
                    if (i == 0)
                    {
                        tr.Cells.Add(DepartmentCell);
                    }
                    HtmlTableCell vehicleCell = new HtmlTableCell();

                    VehicleInfo vinfo = Vehicle.GetDetail(vehicleList[i].VehicleID);

                    vehicleCell.InnerHtml = vinfo.VehicleName + "<br>【" + vinfo.NumberPlate + "】";
                    vehicleCell.Attributes.Add("style", "border-color:#888888;border-collapse:  collapse; padding: 10px; white-space:nowrap;  border-width: 1px; border-style:solid;text-align: left;");

                    tr.Cells.Add(vehicleCell);

                    HtmlTableCell RemarkCell = new HtmlTableCell();
                    RemarkCell.InnerHtml = vehicleList[i].Remark;

                    if (date > vehicleList[i].MendTime.Date)
                    {
                        TimeSpan ts = date.Date - vehicleList[i].MendTime.Date;
                        RemarkCell.InnerHtml += "<br/><span style='color:red;' > 上报时间：" + vehicleList[i].MendTime.ToString("yyyy年MM月dd日") + "，距今已" + ts.Days + "天</span> ";
                    }

                    RemarkCell.Attributes.Add("style", "border-color:#888888;border-collapse:  collapse; padding: 10px; white-space:nowrap;  border-width: 1px; border-style:solid;text-align: left;");

                    tr.Cells.Add(RemarkCell);
                    HtmlTableCell OKCell = new HtmlTableCell();
                    OKCell.InnerHtml = vehicleList[i].DZDOk + "<br/>";
                    OKCell.Attributes.Add("style", "width:20% ;border-color:#888888;border-collapse:  collapse; padding: 10px; white-space:nowrap;  border-width: 1px; border-style:solid;text-align: left;");

                    tr.Cells.Add(OKCell);

                    table.Rows.Add(tr);


                }
                DepartmentCell.RowSpan = vehicleCount;

            }

            //未填写中队
            List<string> NoReportDepartments = VehicleDayItem.GetNoReportDepartment(date, DepartmentId);
            string Departmentstr = "";
            for (int i = 0; i < NoReportDepartments.Count; i++)
            {
                Departmentstr += NoReportDepartments[i] + "&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            lblDeparment.Text = Departmentstr;
        }
        else
        {

            return;
        }
    }
    protected void rblDepartmentId_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindData();
    }
}
